import React, { useImperativeHandle } from "react";
import { Form, Input } from 'antd';
import { IOuterCreateOrEditProps } from "vendor/components/pro-table";

const layout = {
    labelCol: { span: 6 },
    wrapperCol: { span: 16 },
};

export const CreateOrEdit: IOuterCreateOrEditProps["CreateOrEditContent"] = React.forwardRef(({rowKey, values}, actionRef) => {
    const [ form ] = Form.useForm();
    useImperativeHandle(actionRef, () => ({
        getFormData: () => new Promise((resolve, reject) => {
            form.validateFields().then((data) => {
                resolve(data);
            }).catch((e) => {
                reject(new Error("请检查参数"));
            });
        })
    }));

    return (
        <Form {...layout} initialValues={values} form={form}>
            <Form.Item
                label="名称"
                name="name"
                rules={[{ required: true, message: '请填写名称!' }]}
            >
                <Input />
            </Form.Item>
        </Form>
    )
});
